package com.yjyw.tiexie.wxapi;

import android.content.Intent;
import android.os.Bundle;

import com.yjyw.tiexie.bean.event.TCVodPlayerFragmentEvent;
import com.yjyw.tiexie.util.LogUtil;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.umeng.socialize.weixin.view.WXCallbackActivity;

import org.greenrobot.eventbus.EventBus;

public class WXEntryActivity extends WXCallbackActivity implements
        IWXAPIEventHandler {
    private static final String TAG = "WXEntryActivity";

    private IWXAPI api;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        api = WXAPIFactory.createWXAPI(this,"");
        api.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq baseReq) {
        LogUtil.d(TAG, "BaseReq, BaseReq = " + baseReq.openId);
    }

    @Override
    public void onResp(BaseResp resp) {
        LogUtil.d(TAG, "onPayFinish, errCode = " + resp.errCode + "resp.getType()= " + resp.getType());
        if (resp.getType() == ConstantsAPI.COMMAND_LAUNCH_WX_MINIPROGRAM) {//判断小程序回调
            //从小程序回来了
            //礼物充值的刷新
            EventBus.getDefault().post(new TCVodPlayerFragmentEvent("2"));
            //发消息更新 单个视频购买弹框
            EventBus.getDefault().post(new TCVodPlayerFragmentEvent("3"));
        }
        finish();
    }

}
